import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { FontUtil } from "../../../common/font/FontUtil";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Alert } from "../../../../com/mui/controls/Alert";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
type int = number;
//class RevivalPropWindow
    
    export  class RevivalPropWindow extends BaseWindow
    {
        constructor()
        {
            super();
            setSize(280, 195);
            title = Language.getString(20812);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            super.createChildren();
            loc1 = new Object /* flash.display.Sprite */();
            loc1.x = 17;
            loc1.y = 42;
            addChild(loc1);
            loc2 = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            loc2.x = 0;
            loc2.y = 0;
            loc2.width = 245;
            loc2.height = 140;
            loc1.addChild(loc2);
            this._goldTxt = ObjCreate.createGTextField("", 82, 36, 30, 20, loc1, new GTextFormat("", 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._goldTxt.selectable = false;
            this._goldTxt.text = "10";
            this._propTxt = ObjCreate.createGTextInput(164, 36, 30, 18, loc1);
            this._propTxt.text = "1";
            this._propTxt.restrict = "0-9";
            this._propTxt.addEventListener(flash.events.Event.CHANGE, this.onPropNumChangeHandler);
            var loc3=new GLabel();
            loc3.x = 0;
            loc3.y = 15;
            loc3.width = 240;
            loc3.height = 100;
            loc3.mouseChildren = false;
            loc3.mouseEnabled = false;
            loc3.textField.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, null, null, null, null, null, null, null, null, null, null, 6);
            var loc4=Language.getString(20813);
            loc3.htmlText = loc4;
            loc1.addChild(loc3);
            var loc5;
            (loc5 = ObjCreate.createGButton(Language.getString(69901), 50, 105, 60, 25, loc1, "Button")).addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            var loc6;
            (loc6 = ObjCreate.createGButton(Language.getString(69902), 140, 105, 60, 25, loc1, "Button")).addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnHandler);
            return;
        }

        /* internal  */onPropNumChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=parseInt(this._propTxt.text);
            if (loc1 <= 99) 
            {
                this._goldTxt.text = (loc1 * 10).toString();
            }
            else 
            {
                this._goldTxt.text = "990";
                this._propTxt.text = "99";
            }
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var propNum: int;
            var gold: int;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            propNum = parseInt(this._propTxt.text);
            gold = Cache.instance.role.money.gold + Cache.instance.role.money.goldBind;
            if (gold >= propNum * 10) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Role_Relive_SureBuyProp, propNum));
            }
            else 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getString(20814), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal  */onCancelBtnHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.Role_Relive_CancelBuyProp));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._goldTxt.text = "10";
            this._propTxt.text = "1";
            return;
        }

        /* internal */ /* var */_goldTxt: GTextFiled;

        /* internal */ /* var */_propTxt: GTextInput;
    }
